<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
         //数组的排序
         let arrays=[12,551,45,745,14,33,21];
        //  console.log(arrays.sort());// [12, 14, 21, 33, 45, 551, 745]

        //从大到小
        console.log(arrays.sort().reverse());//[745, 551, 45, 33, 21, 14, 12]

        //用方法来写
        console.log(arrays.sort(function(a,b){
            return a-b;  //a-b=-1,按字典顺序来排序，a小b大，就是从小到大
            // return b-a;//倒序

        }));

        console.log("____________________");
        //来排序对象
        let shop=[{name:"唐玮",price:500000},
                  {name:"华少",price:250},
                  {name:"彩霞",price:2000}];
        shop=shop.sort(function(a,b){
            return a.price-b.price;//从小到大
        });
        console.table(shop);

        //值类型的数组用for循环不会改变原来的大小，但是引用类型的数组会改变，因为引用类型有地址
    </script>
</body>
</html>